<template>
	<view class="details">
		<image :src="userInfo.avatar" style="width: 200rpx; height: 200rpx;border-radius: 50%;" mode="aspectFill">
		</image>
		<view class="setting">
			<h3>基本信息</h3>
			<view class="flex add" v-if="userInfo.friends">
				<p>是否设置管理员</p>
				<u-switch v-model="userInfo.friends.role" @change="administrators" :activeValue="1"
					:inactiveValue="0"></u-switch>
			</view>
		</view>
		<view class="details_info">
			<h3>设备情况</h3>
			<view class="phone flex">
				<p>手机号码</p>
				<p>{{ userInfo.mobile }}</p>
			</view>
			<view class="phone flex">
				<p>用户名</p>
				<p>{{ userInfo.nickname }}</p>
			</view>
			<!-- <view class="phone">
        <p>手机号码</p>
        <p>手机号码</p>
      </view>
      <view class="phone">
        <p>手机号码</p>
        <p>手机号码</p>
      </view>
      <view class="phone">
        <p>手机号码</p>
        <p>手机号码</p>
      </view> -->
		</view>
		<view class="deleteBtn">
			<u-button shape="circle" type="error" text="删除好友" :loading="loadingDelete" :disabled="loadingDelete"
				@click="show = true"></u-button>
		</view>
		<u-toast ref="uToast"></u-toast>
		<u-modal :show="show" title="提示">
			<view class="slot-content">
				确认删除好友？
			</view>
			<view class="flex" slot="confirmButton">
				<u-button text="取消" type="info" shape="circle" @click="show = false" style="width:45%"></u-button>
				<u-button text="确定" type="error" shape="circle" @click="deleteFriend" style="width:45%"></u-button>
			</view>
		</u-modal>
	</view>
</template>

<script>
	import {
		friendsDetails,
		friendsDelete,
		friendsUpdateRole,
		friendsOnlineStatus,
	} from "@/common/api/index";
	export default {
		name: "friendDetails",
		components: {},
		data() {
			return {
				userInfo: {},
				loading: false,
				loadingDelete: false,
				show: false
			};
		},
		onLoad(options) {
			this.getDetails(options.friend_updateId);
		},
		computed: {},
		watch: {},
		methods: {
			async getDetails(id) {
				let formData = {
					friend_id: id,
				};
				let res = await friendsDetails(formData);
				console.log("details", res);
				if (res.code === 1) {
					this.userInfo = res.data;
				}
			},
			// 删除好友
			async deleteFriend() {

				this.loadingDelete = true;
				const formData = {
					friend_id: this.userInfo.friends.friend_id,
				};
				const {
					code,
					data,
					msg
				} = await friendsDelete(formData);
				console.log(code, data, msg);
				this.$refs.uToast.show({
					type: code === 1 ? "success" : "error",
					message: msg,
					complete() {
						uni.switchTab({
							url: "/pages/friends/friends",
						});
					},
				});
				this.loadingDelete = false;
			},
			// 设置管理员
			async administrators(e) {
				console.log(e);
				this.loading = true;
				const formData = {
					friend_id: this.userInfo.friends.friend_id,
					role: e,
				};
				let res = await friendsUpdateRole(formData);
				console.log(res);
				this.$refs.uToast.show({
					type: res.code === 1 ? "success" : "error",
					message: res.msg,
				});
				this.loading = false;
			},
		},
	};
</script>

<style scoped lang="scss">
	.details {
		padding: 50rpx;
		background-color: #f0f0f0;
		//   height: calc(100vh - 100rpx);
		height: 100vh;
		overflow: scroll;
		border-radius: 10px;
		text-align: center;
		box-sizing: border-box;

		/deep/.u-avatar {
			margin: 0 auto;
		}

		.setting {
			margin-top: 30rpx;
			padding: 30rpx 20rpx;
			background-color: #fff;
			box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
			border-radius: 30rpx;
			border: 1px solid #ccc;

			h3 {
				font-size: 36rpx;
				font-weight: 600;
			}

			.add {
				justify-content: space-between;
				padding-top: 20rpx;
				font-size: 28rpx;
			}
		}

		.details_info {
			margin-top: 30rpx;
			padding: 30rpx 20rpx;
			background-color: #fff;
			border-radius: 30rpx;
			border: 1px solid #ccc;
			box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);

			h3 {
				font-size: 36rpx;
				font-weight: 600;
			}

			.phone {
				justify-content: space-between;
				padding: 20rpx 0;
				font-size: 28rpx;
				border-bottom: 1px solid #ddd;
			}
		}

		.deleteBtn {
			margin-top: 30rpx;
			background-color: #f0f0f0;
			height: 100rpx;
			display: flex;
			justify-content: center;
			align-items: center;
			width: 75%;
			padding: 0 30rpx;
			box-sizing: border-box;
			width: 100%;
		}
	}
</style>